package com.livestocksolutions.ui;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.WindowConstants;

import java.awt.BorderLayout;

import javax.swing.JSeparator;
import javax.swing.SwingConstants;

import com.livestocksolutions.util.Table;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Show the about window.
 * @author Ken DeVries
 * @author Adam Parr
 * 
 * @.modified 23 October 2012
 */
public class AboutFrame extends JFrame {
	/**
	 * Name of application
	 */
	public static final String APPLICATION = "Beef Cattle Management - Livestock Solutions";
	/**
	 * The Version of the PC UI
	 */
	public static final String VERSION = "0.94";
	/**
	 * The Authors of this Application
	 */
	public static final String AUTHORS = "Ken DeVries,\nMatt Lang,\nJason O\'Dea,\nAdam Parr,\nJosh Swift";
	/**
	 * Packages used by this Application
	 */
	public static final String PACKAGES = 	"GSON (https://sites.google.com/site/gson/Home) for serialisation of data between platforms.\n" +
											"JDatePicker (http://sourceforge.net/projects/jdatepicker/) for date fields\n" +
											"JFreeChart (http://www.jfree.org/jfreechart/) for report display";

	private static final long serialVersionUID = 1L;

	/**
	 * Constructor.
	 */
	public AboutFrame(){
		setTitle("About");
		setIconImage(MainFrame.getImage(MainFrame.APP_ICON));
		setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		setSize(500,150);
		setMinimumSize(getSize());
		setMaximumSize(getSize());
		setLocationRelativeTo(null);
		
		JLabel versionLabel = new JLabel("Version:");
		versionLabel.setVerticalAlignment(SwingConstants.TOP);
		JLabel version = new JLabel(VERSION);
		version.setVerticalAlignment(SwingConstants.TOP);
		
		Table about = new Table(APPLICATION,true,versionLabel,version);
		about.setHeaderClickable(0, false);
		about.setHeaderClickable(1, false);
		about.setOpaque(false);
		
		JLabel authorLabel = new JLabel("Authors:");
		authorLabel.setVerticalAlignment(SwingConstants.TOP);
		JLabel authors = new JLabel("<html><body>"+AUTHORS.replaceAll("\n", "<br>")+"</body></html>");
		authors.setVerticalAlignment(SwingConstants.TOP);
		about.addRow(authorLabel,authors);
		about.setRowClickable(false);
		
		JLabel packageLabel = new JLabel("Uses:");
		packageLabel.setVerticalAlignment(SwingConstants.TOP);
		JLabel packages = new JLabel("<html><body>"+PACKAGES.replaceAll("\n", "<br>")+"</body></html>");
		packages.setVerticalAlignment(SwingConstants.TOP);
		about.addRow(packageLabel,packages);
		about.setRowClickable(false);

		JPanel panel = new JPanel();
		getContentPane().add(panel, BorderLayout.WEST);
		panel.setLayout(new BorderLayout(5, 0));
		
		JLabel lblImage = new JLabel(MainFrame.getImageIcon(MainFrame.APP_ICON));
		lblImage.setVerticalAlignment(SwingConstants.TOP);
		panel.add(lblImage, BorderLayout.WEST);
		
		JSeparator separator = new JSeparator();
		separator.setOrientation(SwingConstants.VERTICAL);
		panel.add(separator, BorderLayout.EAST);
		
		JPanel panel_1 = new JPanel();
		getContentPane().add(panel_1, BorderLayout.CENTER);
		panel_1.setLayout(new BorderLayout(5, 0));
		
		panel_1.add(about, BorderLayout.NORTH);
		
		JPanel panel_2 = new JPanel();
		getContentPane().add(panel_2, BorderLayout.SOUTH);
		panel_2.setLayout(new BorderLayout(0, 0));
		
		JSeparator separator_1 = new JSeparator();
		panel_2.add(separator_1, BorderLayout.NORTH);
		
		JPanel panel_3 = new JPanel();
		FlowLayout flowLayout = (FlowLayout) panel_3.getLayout();
		flowLayout.setAlignment(FlowLayout.RIGHT);
		panel_2.add(panel_3, BorderLayout.CENTER);
		
		JButton btnOK = new JButton("OK");
		panel_3.add(btnOK);
		
		btnOK.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				dispose();
			}
		});
		
		pack();
	}

}
